const express = require('express')

const multer = require('multer');

const app = express()

const cors = require('cors')

app.use(cors())

app.use(express.json())

const bookRouter = require('./router/Book')
const uploadimg = require('./router/uploadImg')
const BookManage = require('./router/BookManage')
const user = require('./router/user')

const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, __dirname+'/public/upload')
  },
  filename: function (req, file, cb) {    
    cb(null, file.fieldname + '-' + Date.now()+'.jpg')
  }
})

const upload = multer ({ storage: storage })

app.use('/api',upload.single('upload'),uploadimg)

app.use('/api',bookRouter,user,BookManage)

//用于将文件夹中的数据静态展示出去，需要对应数据就直接拼上文件夹名称加数据名称
app.use(express.static("./public"));

app.listen(3007,function(){
  console.log('api server running at http://127.0.0.1:3007');
})